package config

import (
	"log"
	"model"
	"spirit/web/core"
	"sync"
)

var Organs = [5]map[string]interface{}{}
var Menus = make(map[string]interface{}, 0)
var ExportConfig model.Dataexport_Field
var ScreenConfig = make(map[string]interface{}, 0)
var CurrentIndicator = make([]map[string]interface{}, 0) //当前年度指标
var CurrentYear string                                   //当前年度
var TbBaseName string                                    //筛查信息表名
var TbBaseName2 string                                   //院内患者筛查信息记录表名
var ScreenYearRecord []string                            //筛查年份记录
var ScreenExcludeYear []string                           //筛查信息录入时候排除该年份的人员缓存信息(即哪些年的人可以重复参加筛查)
var IdCardCaches = sync.Map{}

//const TbBaseName = "infoCollection_"
//const TbBaseName2 = "infoCollection2_"

func init() {
	log.Println("读取系统机构信息....")
	err := core.ReadConfig("./organ.json", &Organs)
	if err == nil {
		log.Println("读取系统机构配置信息成功......")
	} else {
		log.Println("读取系统机构配置信息出错:", err)
	}

	log.Println("读取系统菜单信息....")
	err = core.ReadConfig("./menus.json", &Menus)
	if err == nil {
		log.Println("读取系统菜单信息成功......")
	} else {
		log.Println("读取系统菜单信息出错:", err)
	}

	log.Println("读取导出配置项信息....")
	err = core.ReadConfig("./dataexportconfig.json", &ExportConfig)
	if err == nil {
		log.Println("读取导出配置信息成功......")
	} else {
		log.Println("读取导出配置信息出错:", err)
	}

	log.Println("读取Screen配置项信息....")
	err = core.ReadConfig("./screen.json", &ScreenConfig)
	if err == nil {
		log.Println("读取Screen配置信息成功......")
	} else {
		log.Println("读取Screen配置信息出错:", err)
	}
	CurrentYear = ScreenConfig["currentYear"].(string)
	screenYearRecordTmp := ScreenConfig["screenYearRecord"].([]interface{})
	screenExcludeYearTmp := ScreenConfig["screenExcludeYear"].([]interface{})
	if len(screenYearRecordTmp) > 0 {
		for _, year := range screenYearRecordTmp {
			ScreenYearRecord = append(ScreenYearRecord, year.(string))
		}
	}

	if len(screenExcludeYearTmp) > 0 {
		for _, year := range screenExcludeYearTmp {
			ScreenExcludeYear = append(ScreenExcludeYear, year.(string))
		}
	}
	TbBaseName = "infoCollection_" + CurrentYear
	TbBaseName2 = "infoCollection2_" + CurrentYear
}
